package JDBC;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Hom1 {
    public static void main(String[] args) throws SQLException {
        List<Emp> list = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入员工编号:");
        int id = sc.nextInt();
        String sql = "select e.ename,e.deptno,d.dname from emp e,dept d where e.deptno=d.deptno and e.empno=" + id;

        Connection conn = BaseDB.getConn();
        Statement st = conn.createStatement();
        ResultSet rs = st.executeQuery(sql);

        while (rs.next()) {
            Dept dept = new Dept();
            Emp emp = new Emp();
            emp.setEname(rs.getString("ename"));
            emp.setDeptno(rs.getInt("deptno"));
            dept.setDname(rs.getString("dname"));
            emp.setDept(dept);
            list.add(emp);
        }

        for (Emp em : list) {
            System.out.println(em.getEname()+"  "+em.getDeptno()+"   "+em.getDept().getDname());
        }
    }
}
